package com.hzhc.controller.trainplan;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.entity.TrainPlanDetail;
import com.hzhc.entity.TrainPlanZcdetail;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.TrainPlanZcdetailService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.TrainPlanDetailVo;
import com.hzhc.vo.TrainPlanVo;
import com.hzhc.vo.TrainPlanZcdetailVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 装车计划预导入集装箱 前端控制器
 * </p>
 *
 * @author 功不唐捐
 * @since 2025-03-21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/trainPlanZcdetail")
public class TrainPlanZcdetailController extends BaseController {
    private final TrainPlanZcdetailService trainPlanZcdetailService;

    /**
     * 装车计划
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getDetailList")
    @ResponseBody
    public ResultUtil<List<TrainPlanZcdetailVo>> getDetailList(HttpServletRequest request, @RequestBody TrainPlanZcdetailVo vo){
        Page<TrainPlanZcdetailVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<TrainPlanZcdetailVo> list = trainPlanZcdetailService.getDetailList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }


    /**
     * 卸车导入清单 check
     * @param file
     * @param request
     * @return
     */
    @RequestMapping("/cntrUploadCheck")
    public ResultUtil<List<TrainPlanZcdetailVo>> cntrUploadCheck(MultipartFile file, HttpServletRequest request){
        UserDto user = TokenUtil.getUser(request);
        return trainPlanZcdetailService.cntrUploadCheck(file);
    }

    /**
     * 装车计划 箱信息导入
     * @param request
     * @param list
     * @return
     */
    @PostMapping("/importZcTrainPlanCntr")
    public ResultUtil<T> importZcTrainPlanCntr(HttpServletRequest request, @RequestBody List<TrainPlanZcdetail> list){
        return trainPlanZcdetailService.importZcTrainPlanCntr(request,list);
    }

    @RequestMapping("/updatePoolCntr")
    public ResultUtil<T> updatePoolCntr(HttpServletRequest request,@RequestBody TrainPlanZcdetail detail){
        Long userID = TokenUtil.getUserID(request);
        return trainPlanZcdetailService.updatePoolCntr(detail);
    }

    @GetMapping("/deleteZcCntr/{id}")
    public ResultUtil<T> deleteZcCntr(@PathVariable Long id){
        return trainPlanZcdetailService.deleteZcCntr(id);
    }
}
